package cn.school.newExam.service.impl;

import cn.school.common.utils.SysUserUtils;
import cn.school.newExam.dao.ExamCommentMapper;
import cn.school.newExam.entity.ExamComment;
import cn.school.newExam.entity.ExamScore;
import cn.school.newExam.service.ExamCommentService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ExamCommentServiceImpl extends ServiceImpl<ExamCommentMapper, ExamComment> implements ExamCommentService {
    @Override
    public int addOrUpdate(ExamComment examComment) {
        String username = SysUserUtils.getSysUser().getUsername();
        if(examComment.getId() == null || examComment.getId() == 0l) {
            examComment.setCreateBy(username);
            examComment.setCreateTime(new Date());
            return this.baseMapper.insert(examComment);
        }
        examComment.setModifyBy(username);
        examComment.setModifyTime(new Date());
        return this.baseMapper.updateById(examComment);
    }

    @Override
    public ExamComment getExamComment(ExamComment dto) {
        LambdaQueryWrapper<ExamComment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(dto.getStudentId() != null,ExamComment::getStudentId,dto.getStudentId());
        queryWrapper.eq(dto.getExamPlanId() != null,ExamComment::getExamPlanId,dto.getExamPlanId());
        queryWrapper.eq(dto.getClassId() != null,ExamComment::getClassId,dto.getClassId());
        ExamComment examComment = this.baseMapper.selectOne(queryWrapper);
        return examComment;
    }
}
